import 'package:app_base_page/app_base_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:main_page/class_item.dart';
import 'package:main_page/res.dart';
import 'package:base_router_helper/base_router_helper.dart';
import 'package:url_path/url.dart';
import 'package:fluro/fluro.dart';

/**
 *
 * @ProjectName:    main_page
 * @ClassName:      home_page
 * @Description:    dart类作用描述
 * @Author:         孙浩
 * @QQ:             243280864
 * @CreateDate:     2020/11/23 12:18 AM
 */
class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends BasePage<HomePage> {
  List<ClassItem> dataList = [
    ClassItem("新任经理角色认知", Res.new_manager, color: Color(0XFFBCCBC4)),
    ClassItem("团队组建", Res.team_work, color: Color(0XFF9BA3C3)),
    ClassItem("用人育人", Res.teacher, color: Color(0XFF7F98AD)),
    ClassItem("过程管理", Res.flow_path, color: Color(0XFFD24C88).withOpacity(0.7)),
    ClassItem("高效会议", Res.meeting, color: Color(0XFF387EDA).withOpacity(0.6)),
    ClassItem("冲突管理", Res.fighting),
    ClassItem("促动工坊", Res.product, color: Color(0XFFF1E6C3).withOpacity(0.6)),
    ClassItem("反思总结", Res.think, color: Color(0XFF00F4FE).withOpacity(0.6)),
  ];

  GlobalKey<ScaffoldState> scaffKey = GlobalKey<ScaffoldState>();

  @override
  GlobalKey<ScaffoldState> initKey() {
    // TODO: implement initKey
    return scaffKey;
  }

  @override
  bool pageV() => false;

  @override
  Widget initPageBody(BuildContext c) => Row(
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                SizedBox(
                  height: 80,
                ),
                Text(
                  "储备管理干部培训\n个人汇报总结",
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                  textAlign: TextAlign.end,
                ),
                SizedBox(
                  height: 40,
                ),
                Text(
                  "讲述人：孙浩",
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                )
              ],
            ),
          ),
          VerticalDivider(
            width: 1,
            color: Colors.blueGrey,
          ),
          Expanded(
              child: GridView.builder(
                  padding: EdgeInsets.all(40),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      childAspectRatio: 5 / 2,
                      crossAxisCount: 2,
                      crossAxisSpacing: 20,
                      mainAxisSpacing: 40),
                  itemCount: dataList.length,
                  itemBuilder: (ctx, index) => GestureDetector(
                        child: buildItemBody(index),
                        onTap: () {
                          if (dataList[index].name == "冲突管理") {
                            scaffKey.currentState.showSnackBar(SnackBar(
                              behavior: SnackBarBehavior.floating,
                              content: Text("你没有解锁当前模块哦~"),
                              backgroundColor: Colors.grey,
                              duration: Duration(seconds: 1),
                            ));
                          } else {
                            String routePath = "";
                            switch (dataList[index].name) {
                              case "新任经理角色认知":
                                routePath = StaticRoutePath.managementPath;
                                break;
                              case "团队组建":
                                routePath = StaticRoutePath.team;
                                break;
                              case "用人育人":
                                routePath = StaticRoutePath.teach;
                                break;
                              case "过程管理":
                                routePath = StaticRoutePath.progress_manage;
                                break;
                              case "高效会议":
                                routePath = StaticRoutePath.meeting;
                                break;
                              case "促动工坊":
                                routePath = StaticRoutePath.project_work;
                                break;
                              case "反思总结":
                                routePath = StaticRoutePath.thinking;
                                break;
                            }
                            NavigationUtil.push2page(c, routePath,
                                params: {"imgPath": dataList[index].path},
                                transition: TransitionType.cupertino);
                          }
                        },
                      )))
        ],
        crossAxisAlignment: CrossAxisAlignment.stretch,
      );

  Container buildItemBody(int index) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
                color: dataList[index].color ?? Colors.black12,
                spreadRadius: 3,
                blurRadius: 20)
          ],
          borderRadius: BorderRadius.circular(20)),
      child: Stack(
        children: [
          ConstrainedBox(
            constraints: BoxConstraints.expand(),
            child: ClipRRect(
              child: dataList[index].name == "冲突管理"
                  ? Image.asset(
                      dataList[index].path,
                      fit: BoxFit.cover,
                      color: Colors.grey.withOpacity(0.4),
                      colorBlendMode: BlendMode.dstOut,
                    )
                  : Hero(
                      tag: dataList[index].path,
                      child: Image.asset(
                        dataList[index].path,
                        fit: BoxFit.cover,
                      )),
              borderRadius: BorderRadius.circular(20),
            ),
          ),
          Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  colors: [Colors.transparent, Colors.black45],
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter),
              borderRadius: BorderRadius.circular(20),
            ),
          ),
          Positioned(
            bottom: 10,
            right: 10,
            child: Text(
              dataList[index].name,
              style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  color: Colors.white),
            ),
          )
        ],
      ),
    );
  }

  @override
  initAppbar() => AppBar(
        leading: Hero(
          child: Center(
            child: Image.asset(
              Res.logo,
              height: 30,
              width: 30,
            ),
          ),
          tag: "pageLogo",
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.transparent,
        elevation: 0,
        actions: [
          Row(
            children: [
              Padding(
                padding: EdgeInsets.only(right: 24),
                child: Text(
                  "云袭商学院",
                  style: TextStyle(
                      color: Colors.black,
                      fontWeight: FontWeight.bold,
                      fontSize: 24),
                ),
              )
            ],
          )
        ],
      );
}
